﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Public;
using DLL;


namespace QLBanVe
{
    public partial class AddKhachHang : Form
    {
        public AddKhachHang()
        {
            InitializeComponent();
        }
        KhachHangDLL cls = new KhachHangDLL();
        private void btnThemMoi_Click(object sender, EventArgs e)
        {
            try
            {
                KhachHangPublic p = new KhachHangPublic();
                
                p.MaKhachHang = txtMaHanhKhach.Text.Trim();
                p.TenKhachHang = txtTenKhachHang.Text;
                p.CMND = txtCMND.Text;
                p.DienThoai = txtDienThoai.Text;
                int i = cls.ThemKhachHang(p);
                if (i > 0)
                {
                    txtMaHanhKhach.Text = "";
                    txtTenKhachHang.Text = "";
                    txtDienThoai.Text = "";
                    txtCMND.Text = "";
                    LoadMaAuto();
                }
                else
                    MessageBox.Show("Thất bại");
            }
            catch
            {
                MessageBox.Show("Mã đã tồn tại");
            }
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        void LoadMaAuto()
        { 
            DataTable dt = cls.LoadKhachHang();
            int j = dt.Rows.Count + 1;
            if (j < 10)
            {
                txtMaHanhKhach.Text = "HK0" + j;

            }
            else if (j > 9)
                txtMaHanhKhach.Text = "HK" + j;
        }
        private void AddKhachHang_Load(object sender, EventArgs e)
        {
            txtMaHanhKhach.Enabled = false;
            LoadMaAuto();
                
        }

       

       
    }
}
